home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / oleimpl2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  11.4 KB  |  332 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. // Note: Must include AFXOLE.H first
  12.  
  13. #undef AFX_DATA
  14. #define AFX_DATA AFX_OLE_DATA
  15.  
  16. #if !defined(_WIN32_WCE)
  17. /////////////////////////////////////////////////////////////////////////////
  18. // COleFrameHook - AFX_INTERNAL
  19.  
  20. class COleFrameHook : public CCmdTarget
  21. {
  22. // Construction & Destruction
  23. public:
  24.     COleFrameHook(CFrameWnd* pFrameWnd, COleClientItem* pItem);
  25.  
  26. // Implementation
  27. public:
  28.     ~COleFrameHook();
  29.  
  30.     CFrameWnd* m_pFrameWnd;
  31.     LPOLEINPLACEACTIVEOBJECT m_lpActiveObject;
  32.     COleClientItem* m_pActiveItem;  // item this COleFrameHook is for
  33.     HWND m_hWnd;            // actual HWND this hook is attached to
  34.     BOOL m_bInModalState;   // TRUE if EnableModeless(FALSE) has been called
  35.     BOOL m_bToolBarHidden;  // TRUE if toolbar needs to be shown OnUIDeactivate
  36.     HACCEL m_hAccelTable;   // accelerator to be used while in-place object active
  37.     UINT m_nModelessCount;  // !0 if server's EnableModeless has been called
  38.     CString m_strObjName;   // name of the active in-place object
  39.  
  40. // Overrides for implementation
  41. public:
  42.     virtual void OnRecalcLayout();  // for border space re-negotiation
  43.     virtual BOOL OnPreTranslateMessage(MSG* pMsg);
  44.     virtual void OnActivate(BOOL bActive); // for OnFrameWindowActivate
  45.     virtual BOOL OnDocActivate(BOOL bActive);   // for OnDocWindowActivate
  46.     virtual BOOL OnContextHelp(BOOL bEnter);
  47.     virtual void OnEnableModeless(BOOL bEnable);
  48.     virtual BOOL OnUpdateFrameTitle();
  49.     virtual void OnPaletteChanged(CWnd* pFocusWnd);
  50.     virtual BOOL OnQueryNewPalette();
  51.     virtual BOOL OnInitMenuPopup(CMenu* pMenu, int nIndex, BOOL bSysMenu);
  52.     virtual void OnInitMenu(CMenu* pMenu);
  53.     virtual BOOL OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
  54.  
  55.     // implementation helpers
  56.     BOOL NotifyAllInPlace(
  57.         BOOL bParam, BOOL (COleFrameHook::*pNotifyFunc)(BOOL bParam));
  58.     BOOL DoContextSensitiveHelp(BOOL bEnter);
  59.     BOOL DoEnableModeless(BOOL bEnable);
  60.  
  61. // Interface Maps
  62. public:
  63. #ifdef _AFXDLL
  64.     virtual LPUNKNOWN GetInterfaceHook(const void*);
  65. #endif
  66.  
  67.     BEGIN_INTERFACE_PART(OleInPlaceFrame, IOleInPlaceFrame)
  68.         INIT_INTERFACE_PART(COleFrameHook, OleInPlaceFrame)
  69.         STDMETHOD(GetWindow)(HWND*);
  70.         STDMETHOD(ContextSensitiveHelp)(BOOL);
  71.         STDMETHOD(GetBorder)(LPRECT);
  72.         STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS);
  73.         STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS);
  74.         STDMETHOD(SetActiveObject)(LPOLEINPLACEACTIVEOBJECT, LPCOLESTR);
  75.         STDMETHOD(InsertMenus)(HMENU, LPOLEMENUGROUPWIDTHS);
  76.         STDMETHOD(SetMenu)(HMENU, HOLEMENU, HWND);
  77.         STDMETHOD(RemoveMenus)(HMENU);
  78.         STDMETHOD(SetStatusText)(LPCOLESTR);
  79.         STDMETHOD(EnableModeless)(BOOL);
  80.         STDMETHOD(TranslateAccelerator)(LPMSG, WORD);
  81.     END_INTERFACE_PART(OleInPlaceFrame)
  82.  
  83.     //WINBUG: this interface is here because some applications
  84.     // are broken and require IOleCommandTarget to be
  85.     // implemented before they'll properly activate
  86.     BEGIN_INTERFACE_PART(OleCommandTarget, IOleCommandTarget)
  87.         INIT_INTERFACE_PART(COleFrameHook, OleCommandTarget)
  88.         STDMETHOD(Exec)(const GUID*, DWORD, DWORD,
  89.            VARIANTARG*, VARIANTARG*);
  90.         STDMETHOD(QueryStatus)(const GUID*, ULONG, OLECMD[], OLECMDTEXT*);
  91.     END_INTERFACE_PART(OleCommandTarget)
  92.  
  93.     DECLARE_INTERFACE_MAP()
  94.  
  95.     friend COleClientItem;
  96. };
  97. #endif // _WIN32_WCE
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Helper for implementing OLE enumerators
  101.  
  102. // Note: the following interface is not an actual OLE interface, but is useful
  103. //  for describing an abstract (not typesafe) enumerator.
  104.  
  105. #undef  INTERFACE
  106. #define INTERFACE   IEnumVOID
  107.  
  108. DECLARE_INTERFACE_(IEnumVOID, IUnknown)
  109. {
  110.     STDMETHOD(QueryInterface)(REFIID, LPVOID*) PURE;
  111.     STDMETHOD_(ULONG,AddRef)()  PURE;
  112.     STDMETHOD_(ULONG,Release)() PURE;
  113.     STDMETHOD(Next)(ULONG, void*, ULONG*) PURE;
  114.     STDMETHOD(Skip)(ULONG) PURE;
  115.     STDMETHOD(Reset)() PURE;
  116.     STDMETHOD(Clone)(IEnumVOID**) PURE;
  117. };
  118.  
  119. class CEnumArray : public CCmdTarget
  120. {
  121. // Constructors
  122. public:
  123.     CEnumArray(size_t nSize,
  124.         const void* pvEnum, UINT nCount, BOOL bNeedFree = FALSE);
  125.  
  126. // Implementation
  127. public:
  128.     virtual ~CEnumArray();
  129.  
  130. protected:
  131.     size_t m_nSizeElem;     // size of each item in the array
  132.     CCmdTarget* m_pClonedFrom;  // used to keep original alive for clones
  133.  
  134.     BYTE* m_pvEnum;     // pointer data to enumerate
  135.     UINT m_nCurPos;     // current position in m_pvEnum
  136.     UINT m_nSize;       // total number of items in m_pvEnum
  137.     BOOL m_bNeedFree;   // free on release?
  138.  
  139.     virtual BOOL OnNext(void* pv);
  140.     virtual BOOL OnSkip();
  141.     virtual void OnReset();
  142.     virtual CEnumArray* OnClone();
  143.  
  144. // Interface Maps
  145. public:
  146.     BEGIN_INTERFACE_PART(EnumVOID, IEnumVOID)
  147.         INIT_INTERFACE_PART(CEnumArray, EnumVOID)
  148.         STDMETHOD(Next)(ULONG, void*, ULONG*);
  149.         STDMETHOD(Skip)(ULONG);
  150.         STDMETHOD(Reset)();
  151.         STDMETHOD(Clone)(IEnumVOID**);
  152.     END_INTERFACE_PART(EnumVOID)
  153. };
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. // COleDispatchImpl - IDispatch implementation
  157.  
  158. // Note: This class is only designed to be used as a CCmdTarget member
  159. //  (at the offset specified by CCmdTarget::m_xDispatch))
  160. // It WILL NOT work in other classes or at different offsets!
  161.  
  162. class COleDispatchImpl : public IDispatch
  163. {
  164. public:
  165. #ifndef _AFX_NO_NESTED_DERIVATION
  166.     // required for METHOD_PROLOGUE_EX
  167.     size_t m_nOffset;
  168.     COleDispatchImpl::COleDispatchImpl()
  169.         { m_nOffset = offsetof(CCmdTarget, m_xDispatch); }
  170. #endif
  171.  
  172.     STDMETHOD_(ULONG, AddRef)();
  173.     STDMETHOD_(ULONG, Release)();
  174.     STDMETHOD(QueryInterface)(REFIID, LPVOID*);
  175.  
  176.     STDMETHOD(GetTypeInfoCount)(UINT*);
  177.     STDMETHOD(GetTypeInfo)(UINT, LCID, LPTYPEINFO*);
  178.     STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, UINT, LCID, DISPID*);
  179.     STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*, LPVARIANT,
  180.         LPEXCEPINFO, UINT*);
  181.  
  182.     // special method for disconnect
  183.     virtual void Disconnect();
  184. };
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187. // OLE data (like AUX_DATA)
  188.  
  189. struct OLE_DATA
  190. {
  191.     // OLE 1.0 clipboard formats
  192.     UINT    cfNative, cfOwnerLink, cfObjectLink;
  193.  
  194.     // OLE 2.0 clipboard formats
  195.     UINT    cfEmbeddedObject, cfEmbedSource, cfLinkSource;
  196.     UINT    cfObjectDescriptor, cfLinkSourceDescriptor;
  197.     UINT    cfFileName, cfFileNameW;
  198.  
  199.     //RichEdit formats
  200.     UINT    cfRichTextFormat;
  201.     UINT    cfRichTextAndObjects;
  202.  
  203.     OLE_DATA();
  204. };
  205.  
  206. extern OLE_DATA _oleData;
  207.  
  208. /////////////////////////////////////////////////////////////////////////////
  209. // _AFX_OLE_STATE
  210.  
  211. #undef AFX_DATA
  212. #define AFX_DATA
  213.  
  214. class _AFX_OLE_STATE : public CNoTrackObject
  215. {
  216. public:
  217.     _AFX_OLE_STATE();
  218.     virtual ~_AFX_OLE_STATE();
  219.  
  220.     CView* m_pActivateView;         // activation view
  221.     COleDataSource* m_pClipboardSource;
  222.  
  223.     DWORD m_dwReserved;             // was "parking space" window
  224. #ifdef _AFXDLL
  225.     HINSTANCE m_hInstOLE;       // handle of OLE32.DLL
  226.     HINSTANCE m_hInstOLEAUT;    // handle of OLEAUT32.DLL
  227.     HINSTANCE m_hInstOLEDLG;    // handle of OLEDLG.DLL
  228.     HINSTANCE m_hInstUrlMon;
  229. #endif
  230.     long m_nReserved;           // was reference count on parking window
  231. };
  232.  
  233. EXTERN_PROCESS_LOCAL(_AFX_OLE_STATE, _afxOleState)
  234.  
  235. /////////////////////////////////////////////////////////////////////////////
  236. // Global helper functions
  237.  
  238. // menu merging/unmerging
  239. HMENU AFXAPI AfxMergeMenus(HMENU hMenuShared, HMENU hMenuSource,
  240.     LONG* lpMenuWidths, int iWidthIndex, BOOL bMergeHelpMenus = FALSE);
  241. void AFXAPI AfxUnmergeMenus(HMENU hMenuShared, HMENU hMenuSource,
  242.     HMENU hHelpMenuPopup = NULL);
  243.  
  244. // helpers for IOleCommandTarget
  245.  
  246. #if !defined(_WIN32_WCE)
  247. HRESULT AFXAPI _AfxQueryStatusOleCommandHelper(CCmdTarget* pTarget,
  248.     const GUID* pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[],
  249.    OLECMDTEXT* pcmdtext);
  250. HRESULT AFXAPI _AfxExecOleCommandHelper(CCmdTarget* pTarget,
  251.    const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt,
  252.    VARIANTARG* pvarargIn, VARIANTARG* pvarargOut);
  253. #endif // _WIN32_WCE
  254.  
  255. // helpers for exceptions
  256. void AFXAPI _AfxFillOleFileException(CFileException*, SCODE sc);
  257. void AFXAPI _AfxThrowOleFileException(SCODE sc);
  258.  
  259. // helper used during object creation
  260. LPFORMATETC AFXAPI _AfxFillFormatEtc(LPFORMATETC lpFormatEtc,
  261.     CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtcFill);
  262.  
  263. // helper to copy clipboard data
  264. BOOL AFXAPI _AfxCopyStgMedium(
  265.     CLIPFORMAT cfFormat, LPSTGMEDIUM lpDest, LPSTGMEDIUM lpSource);
  266.  
  267. // helper for reliable and small Release calls
  268. DWORD AFXAPI _AfxRelease(LPUNKNOWN* plpUnknown);
  269. #ifndef _DEBUG
  270. // generate smaller code in release build
  271. #define RELEASE(lpUnk) _AfxRelease((LPUNKNOWN*)&lpUnk)
  272. #else
  273. // generate larger but typesafe code in debug build
  274. #define RELEASE(lpUnk) do \
  275.     { if ((lpUnk) != NULL) { (lpUnk)->Release(); (lpUnk) = NULL; } } while (0)
  276. #endif
  277.  
  278. // helpers from OLESTD.C (from original OLE2UI sample)
  279. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(CLSID clsid, DWORD dwDrawAspect,
  280.     SIZEL sizel, POINTL pointl, DWORD dwStatus, LPCOLESTR lpszFullUserTypeName,
  281.     LPCOLESTR lpszSrcOfCopy);
  282. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(LPOLEOBJECT lpOleObj,
  283.     LPCOLESTR lpszSrcOfCopy, DWORD dwDrawAspect, POINTL pointl, LPSIZEL lpSizelHim);
  284. #if !defined(_WIN32_WCE)
  285. SCODE AFXAPI _AfxOleDoConvert(LPSTORAGE lpStg, REFCLSID rClsidNew);
  286. SCODE AFXAPI _AfxOleDoTreatAsClass(
  287.     LPCTSTR lpszUserType, REFCLSID rclsid, REFCLSID rclsidNew);
  288. DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPPRINTDLG lpPrintDlg);
  289. DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPDEVNAMES pDN, LPDEVMODE pDM);
  290. #endif // _WIN32_WCE
  291. UINT AFXAPI _AfxOleGetUserTypeOfClass(
  292.     REFCLSID rclsid, LPTSTR lpszUserType, UINT cch, HKEY hKey);
  293. DWORD AFXAPI _AfxOleGetLenFilePrefixOfMoniker(LPMONIKER lpmk);
  294. DVTARGETDEVICE* AFXAPI _AfxOleCopyTargetDevice(DVTARGETDEVICE* ptdSrc);
  295. void AFXAPI _AfxOleCopyFormatEtc(LPFORMATETC petcDest, LPFORMATETC petcSrc);
  296. HDC AFXAPI _AfxOleCreateDC(DVTARGETDEVICE* ptd);
  297. void AFXAPI _AfxDeleteMetafilePict(HGLOBAL hMetaPict);
  298. BOOL AFXAPI _AfxOlePropertiesEnabled();
  299.  
  300. // helper(s) for reliable and small QueryInterface calls
  301. LPUNKNOWN AFXAPI _AfxQueryInterface(LPUNKNOWN lpUnknown, REFIID riid);
  302. #define QUERYINTERFACE(lpUnknown, iface) \
  303.     (iface*)_AfxQueryInterface(lpUnknown, IID_##iface)
  304.  
  305. // helpers for conversion between himetric and pixels
  306. #define HIMETRIC_PER_INCH   2540
  307. #define MAP_PIX_TO_LOGHIM(x,ppli)   WCE_FCTN(MulDiv)(HIMETRIC_PER_INCH, (x), (ppli))
  308. #define MAP_LOGHIM_TO_PIX(x,ppli)   WCE_FCTN(MulDiv)((ppli), (x), HIMETRIC_PER_INCH)
  309.  
  310. // helper for GUID comparison
  311. inline BOOL _AfxIsEqualGUID(REFGUID guid1, REFGUID guid2)
  312. {
  313.     return ((DWORD*)&guid1)[0] == ((DWORD*)&guid2)[0] &&
  314.         ((DWORD*)&guid1)[1] == ((DWORD*)&guid2)[1] &&
  315.         ((DWORD*)&guid1)[2] == ((DWORD*)&guid2)[2] &&
  316.         ((DWORD*)&guid1)[3] == ((DWORD*)&guid2)[3];
  317. }
  318.  
  319. HRESULT AFXAPI _AfxReadFromStream(LPSTREAM pStream, void* lpBuf, UINT nCount, DWORD& nRead);
  320.  
  321. /////////////////////////////////////////////////////////////////////////////
  322. // implementation types and constants
  323.  
  324. #define OLE_MAXITEMNAME (_countof("Embedding ")+_countof("4294967295")-_countof(""))
  325.  
  326. typedef LPVOID* LPLP;
  327.  
  328. #undef AFX_DATA
  329. #define AFX_DATA
  330.  
  331. /////////////////////////////////////////////////////////////////////////////
  332.